  <!--<script class="jsbin" src="<?=$url?>datatable/js/jquery.dataTables.js"></script>-->
	<script type="text/javascript" charset="utf-8" src="<?=$url?>datatable/js/FixedColumns.js"></script>
	<script>
  function olah_data(e, i, id_products){
    if (e.keyCode == 13) {
      $.ajax({
        type: 'POST',
        url: '<?=site_url("product/ajax-tanggal")?>',
        async:false,
        beforeSend: function(){
          $("#gif_load").show();
          $("#status_gif").show();
          $("#status_gif_done").hide();
        },
        complete: function(){
          $("#gif_load").hide();
          $("#status_gif").hide();
          $("#status_gif_done").show();
          setTimeout(
            function() 
            {
              $("#status_gif_done").hide("slow");
            }, 5000);
        },
        data: { id_products: id_products, tanggal: i, value: $("#qty_"+i+"_"+id_products).val(), id_outlet: <?=$detail[0]->id_outlet?>, bulan: <?=$detail[0]->month?>, tahun: <?=$detail[0]->year?> }
        }).done(function( msg ) {
            console.log(msg);
          return true;
      });
      <?php
      $tambahan = "0";
      for($k = 1; $k <= $detail[0]->day_in_month; $k++){
        $tambahan .= " + ($('#qty_{$k}_'+id_products).val() * 1)";
      }
//      print $tambahan;die;
      ?>
      var realisasi = <?=$tambahan?>;
      $('#realisasi_service_'+id_products).text(get_dot(realisasi, false));
      var sisa = ($('#stock_'+id_products).text() * 1) - realisasi;
      $('#stock_akhir_'+id_products).text(get_dot(sisa, false));
    }
  }
$(document).ready( function () {
  
	var oTable = $('#example').dataTable( {
		"sScrollY": "500px",
		"sScrollX": "100%",
		"sScrollXInner": "400%",
		"bScrollCollapse": true,
		"bPaginate": false,
    "bSort": false,
    "bFilter": false
	} );
	new FixedColumns( oTable );
} );
	</script>
  <style>
    tr{
      height: 50px;
      border-top: 1px solid black;
    }
    thead th{
      border-left: 1px solid black;
      padding-right: 5px;
    }
    tbody{
      border-left: 1px solid black;
    }
    td{
      border-left: 1px solid black;
      padding-right: 5px;
      padding-left: 5px;
    }
    .edit{
      /*width: 90px;*/
    }
  </style>
  <!--<body id="dt_example">-->
<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
        <div class="widget-block">
        <div class="widget-head">
            <h5><?=$title_table?></h5>
            <div class="widget-control pull-right">
              <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="<?=  site_url("outlet/aktifitas/pica/".$detail[0]->id_actifity_report) ?>"><i class="icon-plus"></i> History</a></li>
                <li><a href="<?=  site_url("outlet/aktifitas/history/".$detail[0]->id_actifity_report) ?>"><i class="icon-plus"></i> PICA</a></li>
                <li><a href="<?=  site_url("outlet/aktifitas/unit-entry-chart/".$detail[0]->id_actifity_report) ?>"><i class="icon-plus"></i> Chart Unit Entry</a></li>
<!--                <li><a href="#"><i class="icon-ok"></i> Active</a></li>
                <li><a href="#"><i class="icon-minus-sign"></i> No-Active</a></li>
                <li><a href="#"><i class="black-icons pdf_document"></i> Export to PDF</a></li>-->
                <li><a href="<?=  site_url("outlet/aktifitas/half-export-xls/".$detail[0]->id_actifity_report) ?>"><i class="black-icons excel_document"></i>XLS (1-15)</a></li>
                <li><a href="<?=  site_url("outlet/aktifitas/fs-export-xls/".$detail[0]->id_actifity_report) ?>"><i class="black-icons excel_document"></i> Export to XLS</a></li>
              </ul>
            </div>
          </div>
          <div>
            <img src="<?=$url?>img/loading_bar.gif" id="gif_load" style="display: none" />
            <span id="status_gif" style="display: none"><b>&nbsp;Saving</b></span>
            <span id="status_gif_done" style="display: none"><b>&nbsp;Saved</b></span>
          </div>
        </div>
      <table cellpadding="0" cellspacing="0" class="display" id="example">
        <thead>
          <tr style="background-color: #8cafed">
            <th align="center" width="200">Product</th>
            <th width="100">Stock Awal</th>
            <?php
            for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
              print "<th width='100' align='right'>{$i}</th>";
            }
            ?>
            <th width="100" align="center">Realisasi</th>
            <th width="100" align="center">Stock Akhir</th>
<!--            <th align="center">Target<br />Hingga <br />Hari Ini</th>
            <th align="center">Achievement</th>
            <th style="border: 0;text-align: left; font-weight: bold" align="center"></th>-->
          </tr>
        </thead>
        <tbody>
          <?php
          foreach($product as $pr){
          ?>
          <tr style="background-color: #0F7">
            <td>&nbsp;&nbsp;&nbsp; <b><?=$pr['name']?></b></td>
            <th></th>
            <?php
            for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
              print "<th></th>";
            }
            ?>
            <th></th>
            <th></th>
          </tr>
          <?php
            foreach($pr['child'] as $child){
              ?>
              <tr>
                <td><?=nl2br($child->name)?></td>
                <td align="right" ><div id="stock_<?=$child->id_products?>"><?=$child->qty?></div></td>
                <?php
                $sum = 0;
                for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
//                  $go_service_perhari = $this->form_eksternal->form_text_editable("qty_".$i."_".$child->id_products, site_url("product/simpan-product/".$child->id_products."/".$i."/".$detail[0]->id_outlet."/".$detail[0]->month."/".$detail[0]->year), number_format($data[$child->id_products][$i], 0, ",", "."), "callback : function(value, settings) {
//        }", "");
                  $go_service_perhari = $this->form_eksternal->form_input("qty_".$i."_".$child->id_products,  number_format($data[$child->id_products][$i], 0, ",", "."), 'id="qty_'.$i.'_'.$child->id_products.'" style="width:40px" onkeypress="olah_data(event, '.$i.', '.$child->id_products.')"');
                  print <<<EOD
                 <td align="right" class="warna_harian">{$go_service_perhari}</td>
EOD;
                 $sum += $data[$child->id_products][$i];
                 $go_service_perhari = "";
                }
                ?>
                <td style="text-align: right; font-weight: bold"><div id="realisasi_service_<?=$child->id_products?>"><?=  number_format($sum, 0, ",", ".")?></div></td>
                <td align="right" ><div id="stock_akhir_<?=$child->id_products?>"><?=($child->qty - $sum)?></div></td>
              </tr>
              <?php
            }
          }
          ?>
          
        </tbody>
      </table>

    </div>
    </div>
  </div>
</div>
<script>
  function get_dot(asli, koma){
    asli = asli.toFixed(0);
    asli = asli.toString();
    var asli_temp = asli.split(".");
    var string = asli_temp[0];
    var string_hasil = "";
    
    var tanda = 0;
    var kl = string.length % 3;
    if(kl == 0)
      kl = 3;
    for(i = 0 ; i < string.length ; i++){
      if(tanda == 3 || i == kl){
        string_hasil = string_hasil + ".";
        tanda = 0;
        kl = 0;
      }
      string_hasil = string_hasil + string[i];
      tanda++;
    }
//    if(koma == true){
      if(!asli_temp[1])
        asli_temp[1] = '';
      
      return string_hasil;
//    }
//    else
//      return string_hasil;
  }
  function kill_dot(string){
    var string_hasil = "";
    for(i = 0 ; i < string.length ; i++){
      if(string[i] != "."){
        if(string[i] == ",")
          string_hasil = string_hasil + ".";
        else
          string_hasil = string_hasil + string[i];
      }
    }
    return string_hasil;
  }
  function sum(kelompok){
    
  }
</script>